home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / nortutil.zip / src / Kibo / orig / kibo.c
C/C++ Source or Header  |  1994-02-22  |  1KB  |  53 lines

  1. /*    kibo.c        program for randomly replacing words on the standard
  2.  *            input with "kibo", appropriately capitalised.
  3.  *            Author:        acb
  4.  *            Commenced:    19-7-1993
  5.  *
  6.  *            This program is part of the Emperor Norton Utilities.
  7.  *            (K) All rites reversed.
  8.  */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <ctype.h>
  12.  
  13. #define ALLCAPS    0
  14. #define nocaps     1
  15. #define Initcap    2
  16.  
  17. char *kibo[] = {"KIBO", "kibo", "Kibo"};
  18.  
  19. #define isdelim(sil) (isspace(sil) || ispunct(sil))
  20.  
  21. #define goahead ((rand()&0x0f) == 1)
  22. /*#define goahead (1)*/
  23.  
  24. char get() {    char c = getchar(); if (c==EOF) exit(0); return c; }
  25.  
  26. int caps(char w[]) {
  27.     if (!isupper(w[0])) return nocaps;
  28.     else if (isupper(w[1])) return ALLCAPS;
  29.     else return Initcap;
  30. }
  31.  
  32. void main() {
  33.     int started=0;
  34.     char word[256];
  35.     while(1) {
  36.         char c;
  37.         int i;
  38.         /* Seek to start of word */
  39.         do { c = get(); if (isdelim(c)) putchar(c); } while isdelim(c);
  40.         if (!started) { srand(started); started = 1; }
  41.         /* Now read in the word */
  42.         i=0;
  43.         do {
  44.             word[i++] = c;
  45.             c=get();
  46.         } while (!isdelim(c));
  47.         word[i]='\0';
  48.         if goahead printf("%s", kibo[caps(word)]);
  49.         else printf("%s", word);
  50.         putchar(c);
  51.     }
  52. }
  53.